<!DOCTYPE html>
<html>
<head>
    <title>首页</title>
    {% include 'system/common/header.html' %}
    <link rel="stylesheet" href="{{ url_for('static', filename='system/admin/css/other/console2.css') }}"/>
</head>
<body class="pear-container">
<div class="layui-row layui-col-space10">
    <div class="layui-col-md2">
        <div class="layui-card">
            <div class="layui-card-header">变更书籍信息</div>
            <div class="layui-card-body">
                <ul class="changed_books">
                    {% for book in data.changed_data %}
                    <a href="/zbook/meilisearch?curr_index={{ data.curr_index }}&bid={{book.id}}" >
                        {% if book.id == data.bid %}
                        <li class="changed_book curr" >
                        {% else %}
                        <li class="changed_book" >
                        {% endif %}
                            《{{ book.name }}》
                            <i class="layui-icon layui-icon-radio" style="color:#f66;"></i>
                        </li>
                    </a>
                    {% endfor %}
                </ul>
            </div>
        </div>
    </div>
    <div class="layui-col-md10">
        <div class="layui-row layui-col-space10">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">
                        索引库
                    </div>
                    <div class="layui-card-body">
                        <div class="layui-row layui-col-space10">
                            {% for k,v in data.indexes.items() %}
                            <div class="layui-col-md2 layui-col-sm2 layui-col-xs2">
                                    {% if k == data.curr_index %}
                                    <div class="pear-card3 curr ">
                                    {% else %}
                                    <div class="pear-card3">
                                    {% endif %}
                                        <a href="#" class="btn close" ><i class="layui-icon  layui-icon-close"></i></a>
                                        <a href="#" class="btn close" ><i class="layui-icon  layui-icon-template-1"></i></a>
                                        <a class="btn close" href="/zbook/meilisearch?curr_index={{ k }}" >
                                            {% if k == data.curr_index %}
                                            <i class="layui-icon layui-icon-ok-circle"></i>
                                            {% else %}
                                            <i class="layui-icon layui-icon-circle"></i>
                                            {% endif %}
                                        </a>
                                        <div class="title">{{ k }}</div>
                                        <div class="count pear-text"> {{ v.numberOfDocuments }} </div>
                                    </div>
                            </div>
                            {% endfor %}
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">文档与索引</div>
                    <div class="layui-card-body">
                        <div class="docs">
                            <ul class="list">
                                {% for doc in data.docs %}
                                <li class="list-item">
                                    <span class="title">
                                    <span> 文档：{{doc.doc.id}} / {{doc.doc.book_id}} / 《{{ doc.doc.book_name }}》 / {{ doc.doc.title }} / {{ doc.doc.sort}} <br/>
                                     索引：{{doc.idoc.id}} / {{doc.idoc.book_id}} / 《{{ doc.idoc.book_name }}》 / {{ doc.idoc.title }} / {{ doc.idoc.sort}} </span>
                                    </span>
                                    <span class="footer">
                                        <a href="javascript:show_diff('{{data.curr_index}}',{{doc.doc.id}});" class="btn pear-btn pear-btn-xs">
                                            <i class="layui-icon layui-icon-template"></i> 对比差异
                                        </a>
                                        <a href="javascript:update_doc('{{data.curr_index}}',{{doc.doc.id}});" class="btn pear-btn pear-btn-xs">
                                            <i class="layui-icon layui-icon-upload-drag"></i> 更新索引
                                        </a>
                                    </span>
                                </li>
                                {% endfor %}
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


</div>
{% include 'system/common/footer.html' %}
<script>
    layui.use(['layer', 'popup'], function () {
        var $ = layui.jquery;
        let popup = layui.popup;

        //setInterval(ajaxPolling, 1000 * 10);
        window.show_diff = function (index, doc_id){
            layer.open({
                type: 2,
                title: '内容差异',
                shade: 0.1,
                area: ['800px', '600px'],
                content: '/zbook/meilisearch/diff?curr_index=' + index + '&did=' + doc_id
            })
        }
        window.update_doc = function (index, doc_id){
                $.ajax({
                    url: '/zbook/meilisearch/update?curr_index=' + index + '&did=' + doc_id,
                    dataType: 'json',
                    type: 'get',
                    success: function (result) {
                        if (result.code == 0) {
                            popup.success(result.msg)
                        } else {
                            popup.failure(result.msg)
                        }
                    }
                })
        }

    });
</script>
</body>
</html>